home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_08_11 / 8n11102a < prev    next >
Text File  |  1990-08-07  |  1KB  |  49 lines

  1.  
  2. *********
  3.  
  4. Listing 2
  5.  
  6. #include <stdio.h>
  7.  
  8. typedef   int  MAT[4][4];
  9.  
  10. main()
  11.    {
  12.      MAT  matA, matB;
  13.      int  i, j, fd, n = 4;
  14.      char *cptr;
  15.  
  16.      puts("\014\n\n ENTER MATRIX ROW BY ROW");
  17.  
  18.      for (i = 0; i < n; ++i)
  19.           for(j = 0; j < n; ++j)
  20.                scanf("%d", &matA[i][j]);
  21.  
  22.      fd = creat("mats.data",4);
  23.  
  24.      cptr = matA;   /*no cast -- even tho the scalar of matA is 32 */  
  25.  
  26.      write(fd, cptr, sizeof(MAT));  /* cptr is taken to be the 
  27.                               pointer to an array of 32 char */ 
  28.  
  29.      close(fd);
  30.  
  31.      fd = open("mats.data",2);
  32.  
  33.      cptr = matB;   /* cptr now points to the other matrix -- no 
  34.                                              cast */
  35.      read(fd, cptr, sizeof(MAT));
  36.      close(fd);
  37.  
  38.      puts("\n\n\n");
  39.      for (i = 0; i < n; ++i)
  40.           {
  41.           for (j = 0; j < n; ++j)             /* 4 x 4 matrix of */
  42.                printf("%4d", matB[i][j]);     /* integers is 
  43.                                                   output */
  44.           putchar('\n');                     /* to screen */
  45.           }
  46.         }
  47.  
  48.  
  49.